package main

import (
	"log"
	"sync"
	"time"
)

func main() {
	cond := sync.NewCond(&sync.Mutex{})

	go func() {
		// 条件锁，可以多个协程同时锁住
		cond.L.Lock()
		log.Println("等待信号1，begin")
		cond.Wait()
		log.Println("等待信号1，end")
		cond.L.Unlock()
	}()

	go func() {
		cond.L.Lock()
		log.Println("等待信号2，begin")
		cond.Wait()
		log.Println("等待信号2，end")
		cond.L.Unlock()
	}()

	//通知等待的协程条件已满足
	time.Sleep(1 * time.Second)
	cond.Broadcast()

	time.Sleep(1 * time.Second)
}
